package com.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.demo.entity.OrderLog;
import com.demo.entity.TbGoods;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * 商品映射器
 */
@Mapper
public interface TbGoodsMapper  extends BaseMapper<TbGoods> {

    @Select("SELECT * FROM tb_goods where goods_id=#{goodsId}")
    TbGoods findById(@Param("goodsId") Long goodsId);


    @Update("UPDATE tb_goods SET goods_stock=#{goodsStock} where goods_id=#{goodsId}")
    int update(@Param("goodsId") Long goodsId, @Param("goodsStock") Integer goodsStock);

    @Insert("insert into order_log(goods_id,order_id,order_num,create_time) values " +
            "(#{goodsId}, #{orderId}, #{orderNum}, #{createTime})")
    int saveLog(@RequestBody OrderLog orderLog);
}
